package com.sc.nft.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.admin.request.SwitchRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.entity.CurrentAffairsType;
import com.sc.nft.entity.dto.CurrentAffairsTypeAddDTO;
import com.sc.nft.entity.dto.CurrentAffairsTypeDTO;
import com.sc.nft.entity.dto.CurrentAffairsTypeEditDTO;
import com.sc.nft.entity.vo.CurrentAffairsTypeVo;
import com.sc.nft.service.CurrentAffairsTypeService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 资讯类型表服务控制器
 *
 * @author zhangchao
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2024-03-06 17:16:12
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/currentAffairsType")
public class CurrentAffairsTypeController {
    private final CurrentAffairsTypeService currentAffairsTypeService;

    @ApiOperation(value = "资讯类型列表", notes = "资讯类型列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsTypeVoPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<CurrentAffairsTypeVo> currentAffairsTypeVoPage(@Valid @RequestBody CurrentAffairsTypeDTO currentAffairsTypeDTO) {
        return PageResult.success(currentAffairsTypeService.currentAffairsTypeVoPage(currentAffairsTypeDTO));
    }

    @ApiOperation(value = "获取类型模块名称", notes = "获取类型模块名称", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getCurrentAffairsTypeVo", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<CurrentAffairsTypeVo>> getCurrentAffairsTypeVo() {
        return Result.success(currentAffairsTypeService.getCurrentAffairsTypeVo());
    }

    @ApiOperation(value = "添加资讯类型", notes = "添加资讯类型", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsTypeAdd", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result currentAffairsTypeAdd(@Valid @RequestBody CurrentAffairsTypeAddDTO currentAffairsTypeAddDTO) {
        CurrentAffairsType currentAffairsType = BeanUtil.copyProperties(currentAffairsTypeAddDTO, CurrentAffairsType.class);
        currentAffairsTypeService.currentAffairsTypeAdd(currentAffairsType);
        return PageResult.success();
    }

    @ApiOperation(value = "修改资讯类型", notes = "修改资讯类型", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsTypeUpdate", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result currentAffairsTypeUpdate(@Valid @RequestBody CurrentAffairsTypeEditDTO currentAffairsTypeEditDTO) {
        CurrentAffairsType currentAffairsType = BeanUtil.copyProperties(currentAffairsTypeEditDTO, CurrentAffairsType.class);
        currentAffairsTypeService.currentAffairsTypeUpdate(currentAffairsType);
        return PageResult.success();
    }

    @ApiOperation(value = "删除", notes = "删除", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsTypeDelete", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result currentAffairsTypeDelete(@Valid @RequestBody IdRequest idRequest) {
        currentAffairsTypeService.currentAffairsTypeDelete(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "是否开启", notes = "是否开启", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsTypeShow", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result currentAffairsTypeShow(@Valid @RequestBody SwitchRequest switchRequest) {
        currentAffairsTypeService.currentAffairsTypeShow(switchRequest.getId(), switchRequest.getSwitchRequest());
        return Result.success();
    }

}